﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Entity;
using Runda.CMS.Bll;
using System.Data;

namespace Runda.CMS.Portal.ContractFollowUp
{
    public partial class ReadRecordForSalsorList : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {                
                BindList(1);
            }
        }
        private void BindList(int pageindex)
        {
            string beginDT = "2010-01-01 00:00:01";
            string endDT = "2020-01-01 00:00:01";
            string Whereclause = " and CustomerID in ( select CustomerID from Cms_Ctrt_CustomerUser where UserID = '"+CurrentUserID.ToString()+"')";
            if (txtInstrumentSerialNum.Text.Trim() != "")
            {
                Whereclause = " and SerialNum like '%" + txtInstrumentSerialNum.Text.Trim() + "%'";
            }
            if (hiddenUserID.Value != "")
            {
                Whereclause = " and CustomerID  ='" + hiddenUserID.Value + "'";
            }
            if (RecordDateFrom.SelectedDate != null)
            {
                beginDT = RecordDateFrom.SelectedDate.ToString();
            }
            if (RecordDateTo.SelectedDate != null)
            {
                endDT = RecordDateTo.SelectedDate.ToString() ;
            }
            int RecordCount = 0;
            DataTable list = new WsmInstrumentRecordBll().GetInstrumentRecord(beginDT, endDT,Whereclause, "CreatedOn desc", AspNetPager1.PageSize, pageindex, out RecordCount);

            RepeaterReadRecord.DataSource = list;
            RepeaterReadRecord.DataBind();
            AspNetPager1.RecordCount = RecordCount;
        }

        protected void RepeaterReadRecord_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "refersh")
            {
                BindList(1);
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindList(AspNetPager1.CurrentPageIndex);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindList(1);
        } 
    }
}
